/*
 *************************************************
 * JavaScript for index.php
 * @author: ducnguyen272@gmail.com
 ************************************************
 */

var $photos;
var currentPhoto = 0;

$(document).ready(function() {
	$photos = $("input:hidden");
	var intervalChangeImages = setInterval(function(){changeImages()}, 5000);
	
	$(".item").each(function( index ) {
		$(this).mouseover( function () {
			clearInterval(intervalChangeImages);
			
			$("#content").css("background-color", "#FFFFFF");
			var photo = $(this).find( 'input:hidden').first().val();
			//$("#cover_photo").hide();
			$("#cover_photo").attr("src",photo);
			$("#cover_photo").fadeIn();
		});
		
		$(this).mouseout( function () {
			$("#content").css("background-color", "");
			$("#cover_photo").attr("src", '');
			intervalChangeImages = setInterval(function(){changeImages()}, 5000);
		});
	});
	
});

function changeImages() {
	if (currentPhoto == 4) {
		currentPhoto = 0;
	}
	var next = currentPhoto + 1;		
	var nextIdx = next - 1;
	
	$("#cover_photo").hide();
	$("#content").css("background-color", "#");
	
	$("#cover_photo").attr("src", $($photos.get(nextIdx)).val());
	
	$("#content").css("background-color", "#FFFFFF");
	$("#cover_photo").fadeIn(500);
	
	currentPhoto++;
}

function setCoverPhoto(url) {
	
}